package com.ruoyi.system.service.impl;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.*;
import com.ruoyi.system.domain.PersonHouse;
import com.ruoyi.system.domain.PersonOtherInfo;
import com.ruoyi.system.domain.PersonPoliceCaseInfo;
import com.ruoyi.system.mapper.PersonHouseMapper;
import com.ruoyi.system.mapper.PersonOtherInfoMapper;
import com.ruoyi.system.mapper.PersonPoliceCaseInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PersoninfoMapper;
import com.ruoyi.system.domain.Personinfo;
import com.ruoyi.system.service.IPersoninfoService;
import com.ruoyi.common.core.text.Convert;

import static com.ruoyi.common.utils.DymicUtils.isLegalDate;

/**
 * 公民基础信息Service业务层处理
 * 
 * @author TYF
 * @date 2023-08-12
 */
@Service
public class PersoninfoServiceImpl implements IPersoninfoService 
{
    @Autowired
    private PersoninfoMapper personinfoMapper;

    @Autowired
    private PersonHouseMapper personHouseMapper;

    @Autowired
    private PersonOtherInfoMapper personOtherInfoMapper;

    @Autowired
    private PersonPoliceCaseInfoMapper personPoliceCaseInfoMapper;

    /**
     * 查询公民基础信息
     * 
     * @param id 公民基础信息主键
     * @return 公民基础信息
     */
    @Override
    public Personinfo selectPersoninfoById(Long id)
    {
        return personinfoMapper.selectPersoninfoById(id);
    }

    /**
     * 查询公民基础信息列表
     * 
     * @param personinfo 公民基础信息
     * @return 公民基础信息
     */
    @Override
    public List<Personinfo> selectPersoninfoList(Personinfo personinfo)
    {
        return personinfoMapper.selectPersoninfoList(personinfo);
    }

    /**
     * 新增公民基础信息
     * 
     * @param personinfo 公民基础信息
     * @return 结果
     */
    @Override
    public int insertPersoninfo(Personinfo personinfo)
    {
        personinfo.setCreateTime(DateUtils.getNowDate());
        personinfo.setCreateBy(String.valueOf(ShiroUtils.getSysUser().getUserId()));
        personinfo.setId(System.currentTimeMillis());
        return personinfoMapper.insertPersoninfo(personinfo);
    }

    /**
     * 修改公民基础信息
     * 
     * @param personinfo 公民基础信息
     * @return 结果
     */
    @Override
    public int updatePersoninfo(Personinfo personinfo)
    {
        personinfo.setUpdateTime(DateUtils.getNowDate());
        personinfo.setUpdateBy(String.valueOf(ShiroUtils.getSysUser().getUserId()));
        return personinfoMapper.updatePersoninfo(personinfo);
    }

    /**
     * 批量删除公民基础信息
     * 
     * @param ids 需要删除的公民基础信息主键
     * @return 结果
     */
    @Override
    public int deletePersoninfoByIds(String ids)
    {
        return personinfoMapper.deletePersoninfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除公民基础信息信息
     * 
     * @param id 公民基础信息主键
     * @return 结果
     */
    @Override
    public int deletePersoninfoById(Long id)
    {
        return personinfoMapper.deletePersoninfoById(id);
    }


    @Override
    public int uploadInfo() {
        int sum =0;
        String jsonData = "E:\\newDevProject\\shga_sample_750k\\person_info.json";
        // 创建一个 Path 对象，表示要读取的文件路径
        Path path = Paths.get(jsonData);
        try {
            // 使用 Files 类的 readAllBytes 方法，将文件的所有字节读取到一个 byte 数组中
            byte[] bytes = Files.readAllBytes(path);
            // 使用 Charset 类的 forName 方法，指定字符编码为 UTF-8，并将 byte 数组转换为字符串
            String json = new String(bytes, Charset.forName("UTF-8"));
            // 打印输出字符串
            String[] split = json.split("\\n");
            List<String> personInfoList = Arrays.asList(split);
            int i=0;
            for(String str:personInfoList){
                PersonInfo person = new PersonInfo();
                str=  str.replaceAll("中等专科学校\\(简称\"中专\"或中等技术学校\\(","中等专科学校(简称'中专'或中等技术学校)")
                .replaceAll("大学本科\\(简称\"大学\"\\)","大学本科(简称'大学')")
                .replaceAll("中等专业学校\\(简称\"中专\"\\)","中等专业学校(简称'中专')");

                if(str.indexOf("身份证")!=-1
                        || str.indexOf("居住证")!=-1
                        || str.indexOf("新旅馆登记照片")!=-1
                        || str.indexOf("驾驶证")!=-1
                        || str.indexOf("边检出境照片")!=-1
                        || str.indexOf("现场办事照片（人员上门）")!=-1
                        || str.indexOf("看守所（正脸）")!=-1
                        || str.indexOf("护照")!=-1
                        || str.indexOf("网吧登记照片")!=-1
                        || str.indexOf("拘留所（正脸）")!=-1
                        || str.indexOf("拘留所（侧脸）")!=-1
                        || str.indexOf("看守所")!=-1
                        || str.indexOf("拘留所")!=-1
                        || str.indexOf("现场办事照片")!=-1
                        || str.indexOf("PHOTO")!=-1){
                    String[] newStrs = str.split(",");
                    List<String> newPersonJson = Arrays.asList(newStrs);
                    List<String> newJson =new ArrayList<>();
                    for(String newStr:newPersonJson){
                        if(newStr.indexOf("PHOTO")==-1 && newStr.indexOf("驾驶证")==-1 && newStr.indexOf("http")==-1 ){
                            newJson.add(newStr);
                        }
                    }

                   String newPersonJsonStr=   newJson.stream().collect(Collectors.joining(","));
                    person=  JsonUtils.jsonToPojo(newPersonJsonStr, PersonInfo.class);
                    System.out.println(newPersonJsonStr);
                }else{
                    person=  JsonUtils.jsonToPojo(str, PersonInfo.class);
                }

                PersonBaseInfo personBaseInfo = person.get_source();
                System.out.println(person);
                Personinfo personinfo =new Personinfo();
                if(StringUtils.isNotEmpty(person.get_id())){
                    personinfo.setBussinessId(person.get_id());
                }
                if(StringUtils.isNotEmpty(String.valueOf(personBaseInfo.getAGE()))){
                    personinfo.setAge(Long.parseLong(String.valueOf(personBaseInfo.getAGE())));
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getIDNO())){
                    personinfo.setBirthday(IDCardUtils.getBirthday(personBaseInfo.getIDNO()));
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getBPLACE())){
                    personinfo.setBirthplace(personBaseInfo.getBPLACE());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getHHPLACE())){
                    personinfo.setHhplace(personBaseInfo.getHHPLACE());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getEDEGREE())){
                    personinfo.setEdegree(personBaseInfo.getEDEGREE());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getESCU())){
                    personinfo.setEscu(personBaseInfo.getESCU());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getHEIGHT())){
                    String[] split1 = personBaseInfo.getHEIGHT().split("\\.");
                    personinfo.setHeight(Long.parseLong(split1[0]));
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getLABELNAMES())){
                    personinfo.setLabelName(personBaseInfo.getLABELNAMES());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getLABS())){
                    personinfo.setLabs(personBaseInfo.getLABS());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getMARR())){
                    personinfo.setMarrige(personBaseInfo.getMARR());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getRNAME())){
                    personinfo.setName(personBaseInfo.getRNAME());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getRELI())){
                    personinfo.setReli(personBaseInfo.getRELI());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getIDTYPE())){
                    personinfo.setIdCardType(personBaseInfo.getIDTYPE());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getPROF())){
                    personinfo.setProfressional(personBaseInfo.getPROF());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getSEX())){
                    personinfo.setSex(personBaseInfo.getSEX());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getIDNO())){
                    personinfo.setIdCard(personBaseInfo.getIDNO());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getNPLACE())){
                    personinfo.setNplace(personBaseInfo.getNPLACE());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getHEAVY())){
                    personinfo.setHeavy(personBaseInfo.getHEAVY());
                }
                if(StringUtils.isNotEmpty(personBaseInfo.getPOLI())){
                    personinfo.setPoliticalOutLook(personBaseInfo.getPOLI());
                }
                personinfo.setSort(Long.parseLong(String.valueOf(person.getSort().get(0))));
              int update =insertPersoninfo(personinfo);
                System.out.println("基础信息是否添加成功:"+update);
              //添加房产信息
                String std_address = personBaseInfo.getSTD_ADDRESS();
                if(StringUtils.isNotEmpty(std_address)){
                    String[] houseArray = std_address.split("\\n");
                    List<String> houseList = Arrays.asList(houseArray);
                    for(String house:houseList){

                        String[] hoseArrays = house.split(" ");
                        List<String> houseManyList = Arrays.asList(hoseArrays);
                        if(houseManyList.size()>1){
                            for(String houseOne:houseManyList){
                                PersonHouse personHouse =new PersonHouse()
                                        .setId(System.currentTimeMillis())
                                        .setPid(personinfo.getId())
                                        .setAddress(houseOne);
                                int i1 = personHouseMapper.insertPersonHouse(personHouse);
                                System.out.println("房产信息添加成功:"+i1);
                            }
                        }else{
                            PersonHouse personHouse =new PersonHouse()
                                    .setId(System.currentTimeMillis())
                                    .setPid(personinfo.getId())
                                    .setAddress(house);
                            int i1 = personHouseMapper.insertPersonHouse(personHouse);
                            System.out.println("房产信息添加成功:"+i1);
                        }



                    }
                }
                i++;
              sum=i;
            }


        } catch (IOException e) {
            // 处理异常
            e.printStackTrace();
        }
        return sum;
    }


    @Override
    public int uploadInfoTelOrAddress() {
        int sum =0;
        String jsonData = "E:\\newDevProject\\shga_sample_750k\\address_merge_with_mobile_data.json";
        // 创建一个 Path 对象，表示要读取的文件路径
        Path path = Paths.get(jsonData);
        try {
            // 使用 Files 类的 readAllBytes 方法，将文件的所有字节读取到一个 byte 数组中
            byte[] bytes = Files.readAllBytes(path);
            // 使用 Charset 类的 forName 方法，指定字符编码为 UTF-8，并将 byte 数组转换为字符串
            String json = new String(bytes, Charset.forName("UTF-8"));
            // 打印输出字符串
            String[] splitJson = json.split("\\n");
            List<String> personInfoList = Arrays.asList(splitJson);
            long startTime = System.currentTimeMillis();
            List<PersonOtherInfo> personOtherSaveInfoList =new ArrayList<>();
            for(int i=0;i<personInfoList.size();i++){
                String newStr = personInfoList.get(i).replaceAll("[\\\"\\{\\}\\[\\]]", "");
                String[] split = newStr.split(",");
                List<String> info = Arrays.asList(split);

                PersonOtherInfo vo =new PersonOtherInfo();
               for(String s:info){

                    //获取数据来源地址
                    if(s.indexOf("DATA_SOURCE")!=-1){
                        String[] sourceArrays = s.split(":");
                        if(sourceArrays.length>1){
                            vo.setDataSource(sourceArrays[1]);
                        }



                    }

                    //获取手机号
                    if(s.indexOf("IDENTITY_VALUE")!=-1){
                        String[] mobileArrays = s.split(":");
                        if(mobileArrays.length>1){
                            vo.setMobile(mobileArrays[1]);
                        }


                    }

                    //获取来源地址
                    if(s.indexOf("SRC_ADDRESS")!=-1){
                        String[] addressArrays = s.split(":");
                        if(addressArrays.length>1){
                            vo.setSrcAddress(addressArrays[1]);
                        }

                    }


                    //获取姓名
                    if(s.indexOf("name")!=-1){
                        String[] nameArrays = s.split(":");
                        List<String> nameList = Arrays.asList(nameArrays);
                        for(String name1:nameList){
                            //根据公民基础信息查询姓名 如果存在 则存储该名字
                           if(!"DETAIL".equals(name1) && !"nameinfo".equals(name1) && !"name".equals(name1)){
                               Personinfo query =new Personinfo();
                               query.setName(name1);
                               List<Personinfo> personinfos = personinfoMapper.selectPersonInfoByName(name1);
                               if(!personinfos.isEmpty()){
                                   Long id = personinfos.get(0).getId();
                                   vo.setName(name1);
                                   vo.setPid(id);
                                   vo.setCreateBy(String.valueOf(ShiroUtils.getSysUser().getUserId()));
                                   vo.setCreateTime(new Date());
                               }else{
                                   vo.setName(name1);
                                   vo.setCreateBy(String.valueOf(ShiroUtils.getSysUser().getUserId()));
                                   vo.setCreateTime(new Date());
                               }

                           }
                        }

                    }
                }
                personOtherSaveInfoList.add(vo);


                if (i % 1000 == 0) {
                    personOtherInfoMapper.saveBatchPersonOtherInfo(personOtherSaveInfoList);
                    // 每 1000 条数据提交一次事务
                    personOtherSaveInfoList.clear();
                }

            }

            // 最后插入剩余的数据
            if(!StringUtils.isEmpty(personOtherSaveInfoList)) {
                personOtherInfoMapper.saveBatchPersonOtherInfo(personOtherSaveInfoList);
            }
            long spendTime = System.currentTimeMillis()-startTime;
            System.out.println("成功插入 30 万条数据,耗时："+spendTime+"毫秒");


        } catch (IOException e) {
            // 处理异常
            e.printStackTrace();
        }
        return sum;
    }

    @Override
    public int uploadInfoCase() {
        int sum =0;
        String jsonData = "E:\\newDevProject\\shga_sample_750k\\case_data_index4.json";
        // 创建一个 Path 对象，表示要读取的文件路径
        Path path = Paths.get(jsonData);
        try {
            // 使用 Files 类的 readAllBytes 方法，将文件的所有字节读取到一个 byte 数组中
            byte[] bytes = Files.readAllBytes(path);
            // 使用 Charset 类的 forName 方法，指定字符编码为 UTF-8，并将 byte 数组转换为字符串
            String json = new String(bytes, Charset.forName("UTF-8"));
            // 打印输出字符串
            String[] split = json.split("\\n");
            List<String> personInfoList = Arrays.asList(split);
            Integer num =0;
            for(String caseInfo:personInfoList){
                // String newStr = caseInfo.replaceAll("[\\\"\\{\\}\\[\\]]", "");
                String replaceCaseInfo = caseInfo.replaceAll("[\\{\\}\\[\\]]", "");
                String[] newJsonStr = replaceCaseInfo.split("\\\"\\,\\\"");
                List<String> jsonList = Arrays.asList(newJsonStr);
                //  StringJoiner bjContent =new StringJoiner("，");
                PersonPoliceCaseInfo personPoliceCaseInfo =new PersonPoliceCaseInfo();
                for(String clonm:jsonList){//切割下来的对应字段
                    //System.out.println(clonm);


                    if(clonm.indexOf("BRIEF_CASE")!=-1){  //处理报警内容
                        String[] brife_case_arrays = clonm.split("\\\"\\:\\\"");
                        List<String> brifeContents = Arrays.asList(brife_case_arrays);
                        String content ="";
                        for(int i=0;i<brifeContents.size();i++){
                            content =brifeContents.get(brifeContents.size()-1);
                            content=   content.replaceAll("rn","");
                        }
                        personPoliceCaseInfo.setCaseContent(content);
                        System.out.println("案件简要>>>>>>"+content);  //数据库对应字段case_content
                    }


                    if(clonm.indexOf("CASE_ADDRESS")!=-1){//处理案件地址
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseAddress ="";
                        for(int i=0;i<strings.size();i++){
                            caseAddress= strings.get(strings.size()-1);
                            caseAddress=      caseAddress.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseAddress(caseAddress);
                        System.out.println("案件地址>>>>>>"+caseAddress);
                    }

                    if(clonm.indexOf("BLOCK")!=-1){//处理案件街道
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseBlock ="";
                        for(int i=0;i<strings.size();i++){
                            caseBlock=strings.get(strings.size()-1);
                            caseBlock=      caseBlock.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseBlock(caseBlock);
                        System.out.println("案件街道>>>>>>"+caseBlock);
                    }
                    if(clonm.indexOf("CASE_NUMBER")!=-1){//处理案件编号
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseNumber ="";
                        for(int i=0;i<strings.size();i++){
                            caseNumber= strings.get(strings.size()-1);
                            caseNumber=      caseNumber.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseNumber(caseNumber);
                        System.out.println("案件编号>>>>>>"+caseNumber);
                    }
                    if(clonm.indexOf("CITY")!=-1){//处理案件市区
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseCity ="";
                        for(int i=0;i<strings.size();i++){
                            caseCity= strings.get(strings.size()-1);
                            caseCity=      caseCity.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseCity(caseCity);
                        System.out.println("案件市区>>>>>>"+caseCity);
                    }
                    if(clonm.indexOf("LOC_SOURCE")!=-1){//处理案件来源
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseSource ="";
                        for(int i=0;i<strings.size();i++){
                            caseSource= strings.get(strings.size()-1);
                            caseSource=      caseSource.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseSource(caseSource);
                        System.out.println("案件来源>>>>>>"+caseSource);
                    }
                    if(clonm.indexOf("NUMBER_L7")!=-1){//处理案件物品编号
                        String[] split2 = clonm.split("\\\"\\:\\\"");

                        List<String> strings = Arrays.asList(split2);
                        String caseitemNumber ="";
                        for(int i=0;i<strings.size();i++){
                            caseitemNumber= strings.get(strings.size()-1);
                            caseitemNumber=      caseitemNumber.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseItemNumber(caseitemNumber);
                        System.out.println("物品编号>>>>>>"+caseitemNumber);
                    }
                    if(clonm.indexOf("PROVINCE_L1")!=-1){//处理案件发生市区
                        String[] split2 = clonm.split("\\\"\\:\\\"");

                        List<String> strings = Arrays.asList(split2);
                        String caseProvince ="";
                        for(int i=0;i<strings.size();i++){
                            caseProvince= strings.get(strings.size()-1);
                            caseProvince=      caseProvince.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseProvince(caseProvince);
                        System.out.println("案件发生市区>>>>>>"+caseProvince);
                    }
                    if(clonm.indexOf("STD_ADDRESS")!=-1){//处理案件发生具体地址
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseStdAddress ="";
                        for(int i=0;i<strings.size();i++){
                            caseStdAddress=strings.get(strings.size()-1);
                            caseStdAddress=      caseStdAddress.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseStdAddress(caseStdAddress);
                        System.out.println("案件发生具体地址>>>>>>"+caseStdAddress);
                    }


                    if(clonm.indexOf("CASE_NAME")!=-1){//处理案件发生名称
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseName ="";
                        for(int i=0;i<strings.size();i++){
                            caseName= strings.get(strings.size()-1);
                            caseName=      caseName.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseName(caseName);
                        System.out.println("案件发生名称>>>>>>"+caseName);
                    }


                    if(clonm.indexOf("BUILDING")!=-1){//处理案件发生楼层
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseBUILDING ="";
                        for(int i=0;i<strings.size();i++){
                            caseBUILDING= strings.get(strings.size()-1);
                            caseBUILDING=      caseBUILDING.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseBuilding(caseBUILDING);
                        System.out.println("案件发生楼层>>>>>>"+caseBUILDING);
                    }


                    if(clonm.indexOf("COUNTY_L3")!=-1){//处理案件发生区域
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseCounty ="";
                        for(int i=0;i<strings.size();i++){
                            caseCounty= strings.get(strings.size()-1);
                            caseCounty=      caseCounty.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseCounty(caseCounty);
                        System.out.println("案件发生区域>>>>>>"+caseCounty);
                    }


                    if(clonm.indexOf("LATITUDE")!=-1){//处理案件经纬度 纬度
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseLatitude ="";
                        for(int i=0;i<strings.size();i++){
                            caseLatitude= strings.get(strings.size()-1);
                            caseLatitude=      caseLatitude.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseLatitude(caseLatitude);
                        System.out.println("案件发生纬度>>>>>>"+caseLatitude);
                    }

                    if(clonm.indexOf("LONGITUDE")!=-1){//处理案件经纬度 经度
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String caseLongitude ="";
                        for(int i=0;i<strings.size();i++){
                            caseLongitude= strings.get(strings.size()-1);
                            caseLongitude=      caseLongitude.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseLongitude(caseLongitude);
                        System.out.println("案件发生经度>>>>>>"+caseLongitude);
                    }


                    if(clonm.indexOf("cjdwmc")!=-1){//处理报警单位受理名称
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String cjdwmc ="";
                        for(int i=0;i<strings.size();i++){
                            cjdwmc= strings.get(strings.size()-1);
                            cjdwmc=      cjdwmc.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseSlDwName(cjdwmc);
                        System.out.println("报警单位受理名称>>>>>>"+cjdwmc);
                    }


                    if(clonm.indexOf("org_name")!=-1){//单位名称
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String org_name ="";
                        for(int i=0;i<strings.size();i++){
                            org_name= strings.get(strings.size()-1);
                            org_name=      org_name.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseOrgName(org_name);
                        System.out.println("单位名称>>>>>>"+org_name);
                    }


                    if(clonm.indexOf("case_address")!=-1){//发生地址
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_address ="";
                        for(int i=0;i<strings.size();i++){
                            case_address= strings.get(strings.size()-1);
                            case_address=      case_address.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseAddress(case_address);
                        System.out.println("发生地址>>>>>>"+case_address);
                    }


                    if(clonm.indexOf("POI_L8")!=-1){//案件物品类型，案件详细地址
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_poi_item_place ="";
                        for(int i=0;i<strings.size();i++){
                            case_poi_item_place= strings.get(strings.size()-1);
                            case_poi_item_place=      case_poi_item_place.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCasePoiItemPlace(case_poi_item_place);
                        System.out.println("案件物品类型，案件详细地址>>>>>>"+case_poi_item_place);
                    }

                    if(clonm.indexOf("ROAD_L5")!=-1){//案件发生的马路街道
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_road ="";
                        for(int i=0;i<strings.size();i++){
                            case_road= strings.get(strings.size()-1);
                            case_road=      case_road.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseRoad(case_road);
                        System.out.println("案件发生的马路街道>>>>>>"+case_road);
                    }


                    if(clonm.indexOf("bjrxm")!=-1){//报警人姓名
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_take_name ="";
                        for(int i=0;i<strings.size();i++){
                            case_take_name= strings.get(strings.size()-1);
                            case_take_name=      case_take_name.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseTakeName(case_take_name);
                        System.out.println("报警人姓名>>>>>>"+case_take_name);
                    }

                    if(clonm.indexOf("bjrlxdh")!=-1){//报警人联系电话
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String bjrlxdh ="";
                        for(int i=0;i<strings.size();i++){
                            bjrlxdh= strings.get(strings.size()-1);
                            bjrlxdh=      bjrlxdh.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseTakeMobile(bjrlxdh);
                        System.out.println("报警人联系电话>>>>>>"+bjrlxdh);
                    }

                    if(clonm.indexOf("zjhm")!=-1){//报警人证件号码
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_take_idCard ="";
                        for(int i=0;i<strings.size();i++){
                            case_take_idCard= strings.get(strings.size()-1);
                            case_take_idCard=      case_take_idCard.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseTakeIdcard(case_take_idCard);
                        System.out.println("报警人证件号码>>>>>>"+case_take_idCard);
                    }


                    if(clonm.indexOf("case_state")!=-1 || clonm.indexOf("caseState")!=-1){//案件状态
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_state ="";
                        for(int i=0;i<strings.size();i++){
                            case_state= strings.get(strings.size()-1);
                            case_state=      case_state.replaceAll("\\\"","");
                        }
                        personPoliceCaseInfo.setCaseStatus(case_state);
                        System.out.println("案件状态>>>>>>"+case_state); //case_type
                    }


                    if(clonm.indexOf("REPORT_TIME")!=-1){//报警时间
                        String[] split2 = clonm.split("\\\"\\:\\\"");
                        List<String> strings = Arrays.asList(split2);
                        String case_time ="";
                        for(int i=0;i<strings.size();i++){
                            case_time= strings.get(strings.size()-1);
                            case_time=      case_time.replaceAll("\\\"","");

                            boolean legalDate = isLegalDate(case_time.length(), case_time, DateUtils.YYYY_MM_DD_HH_MM_SS);
                            if(!legalDate){
                                case_time="";
                            }
                        }
                        personPoliceCaseInfo.setCaseTime(case_time);
                        System.out.println("报警时间>>>>>>"+case_time); //case_type
                    }
                }

                int i = personPoliceCaseInfoMapper.insertPersonPoliceCaseInfo(personPoliceCaseInfo);
                System.out.println("报警信息内容添加成功:"+i);
                System.out.println(">>>>>>>>>>>>>>分割线>>>>>>>>>>>>>>>>>>");
                num++;
                sum=num;
            }
            System.out.println(">>>>>>>>>>>>>>共"+sum+"记录>>>>>>>>>>>>>>>>>>");
        } catch (IOException e) {
            // 处理异常
            e.printStackTrace();
        }

        return sum;
    }
}
